<!-- 角色编辑弹窗 -->
<template>
  <div class="drawerDetail">
    <el-drawer :visible="drawerEditBoolen"
               size="50%"
               :before-close="handleClose"
               ref="drawer"
               :with-header="false">
      <!-- 订单信息 -->
      <el-card class="box-card"
               shadow="never">
        <div slot="header"
             class="clearfix">
          <span>基本信息</span>
        </div>
        <div class="">

          <div class="flex-between">
            <div class="flex-start-center"
                 style=" font-size: 18px;font-weight: 700;color: black;">
              <div style="margin-right:5px;">合伙人姓名:</div>
              <div class="realNameStyle">

                <span>{{orderInfoData?.name  }}</span>
              </div>
            </div>

          </div>

          <div style="margin-top: 30px;"
               class="flex-start-center">
            <div class="line ">

            </div>
            <div style="font-weight: 700;color: black;font-size: 16px;">收益数据</div>
          </div>

          <div class="flex-around"
               style="padding: 25px;">
            <div class="flex-column"
                 style="width: 25%">
              <div>累计收益{{ '('+configBS.currency_name+')' }}</div>
              <div style="color: #1890ff;font-weight: 700;margin-top: 7px;">{{ orderInfoData?.totayIncome }} </div>

            </div>
            <div class="flex-column"
                 style="width: 25%;">
              <div>今日收益{{ '('+configBS.currency_name+')' }}</div>
              <div style="color: #1890ff;font-weight: 700;margin-top: 7px;"> {{ orderInfoData?.todayIncome }} </div>

            </div>
            <div class="flex-column"
                 style="width:25%;">
              <div>昨日收益{{ '('+configBS.currency_name+')' }}</div>
              <div style="color: #1890ff;font-weight: 700;margin-top: 7px;">{{ orderInfoData?.yesterdayIncome }} </div>

            </div>
            <div class="flex-column"
                 style="width: 25%;">
              <div>本月收益{{ '('+configBS.currency_name+')' }}</div>
              <div style="color: #1890ff;font-weight: 700;margin-top: 7px;">{{ orderInfoData?.monthIncome }} </div>

            </div>

          </div>

          <div style="margin-top: 30px;"
               class="flex-start-center">
            <div class="line ">

            </div>
            <div style="font-weight: 700;color: black;font-size: 16px;">推广员数据</div>
            <div style="color: #1890ff;margin-left: 10px;"
                 @click="partnerUserFn(orderInfoData)">查看用户列表</div>
          </div>

          <div class="flex-around"
               style="padding: 25px;">
            <div class="flex-column"
                 style="width: 25%;">
              <div>今日新增推广员(人)</div>
              <div style="color: #1890ff;font-weight: 700;margin-top: 7px;">{{ orderInfoData?.todayAddPromoter }} </div>

            </div>
            <div class="flex-column"
                 style="width: 25%;">
              <div>今日新增用户(人)</div>
              <div style="color: #1890ff;font-weight: 700;margin-top: 7px;"> {{ orderInfoData?.todayAddUser }} </div>

            </div>

            <div class="flex-column"
                 style="width: 25%;">

              <div>累计名下用户(人)</div>
              <div style="color: #1890ff;font-weight: 700;margin-top: 7px;">{{ orderInfoData?.userTotay }} </div>

            </div>
            <div class="flex-column"
                 style="width: 25%;">
              <div>累计推广员(人)</div>
              <div style="color: #1890ff;font-weight: 700;margin-top: 7px;">{{ orderInfoData?.promoterTotay }} </div>

            </div>

          </div>

        </div>
      </el-card>

      <div class="drawer__footer"
           v-if="orderInfoData?.is_authentication == 1"
           :style="{ marginTop: !(radio == 3) ? '100px' : '' }">
        <el-button round
                   type="plain"
                   @click="handleClose"
                   size="medium">返回</el-button>
        <el-button type="primary"
                   round
                   :loading="loading"
                   size="medium"
                   @click="save">确定</el-button>
      </div>
      <!-- <div class="drawer__footer"
			 v-else
			 :style="{marginTop:!(radio==3)?'100px':''}">
		
		</div> -->
    </el-drawer>
    <!-- 图片预览 -->
    <el-image-viewer v-if="viewerVisible"
                     style="z-index: 9999"
                     :on-close="closeViewer"
                     :url-list="imgViewArr" />
    <el-button type="text"></el-button>

    <rolePartnerUserList :data="currentPromoters"
                         :drawerEditBoolen.sync="drawerEditBoolenPromoters"
                         @done="reload" />
  </div>
</template>
  
  <script>
import ElImageViewer from 'element-ui/packages/image/src/image-viewer';
import { associateGetInfo } from '@/api/partnerApi/index'
import rolePartnerUserList from "./role-partnerUserList.vue"
// import {
//   userOssSignature,
//   qnyOssSignature
// } from '@/api/creatCenter/material';
// import { storageConfigDetail } from '@/api/storageInfo/index';

// import axios from 'axios';
// import {
//   siteCategoriesInsert,
//   siteCategoriesList,
//   siteCategoriesModify,
//   siteCategoriesDetail
// } from '@/api/serviceManagement/categoriesList';
import { upload } from '@/api/saveImg/index';
import { userInfo, authentication } from '@/api/userList/index';
export default {
  name: 'pictureEdit',
  components: { ElImageViewer, rolePartnerUserList },
  props: {
    drawerEditBoolen: {
      type: Boolean,
      default: false
    },
    // 修改回显的数据
    data: Object
  },
  data () {
    // const categoryImage = (rule, value, callback) => {
    //   console.log(this.form.img);
    //   if (!this.form.img) {
    //     callback(new Error('请上传图片'));
    //   } else {
    //     callback();
    //   }
    // };
    const DEFAULT_FORM = {
      // 等级名称
      name: '',
      //   描述
      desc: '',
      // 0 普通会员  1 vip会员
      level: '1',
      //  价格
      price: '',
      // 有效期
      effective_time: '',
      // 搭子数量
      dazi_number: '',
      // 圈子数量
      circle_number: '',
      // 服务数量
      service_number: '',
      // 社群数量
      community_number: ''
    };
    return {
      currentPromoters: null,
      drawerEditBoolenPromoters: false,
      configBS: JSON.parse(localStorage.getItem('config')),
      radio: 2,
      storageMode: 2,
      options: [],
      imageUrl: '',
      imgViewArr: [],
      viewerVisible: false,
      // 表单数据
      form: { ...DEFAULT_FORM },
      dialogImageUrl: '',
      fileList: [],
      dialogVisible: false,
      // 表单验证规则
      rules: {
        name: [
          {
            required: true,
            message: '请输入分类名称',
            trigger: 'blur'
          }
        ],

        desc: [
          {
            required: true,
            message: '请输入描述',
            trigger: 'blur'
          }
        ],
        price: [
          {
            required: true,
            message: '请输入价格',
            trigger: 'blur'
          }
        ],
        effective_time: [
          {
            required: true,
            message: '请输入有效时间',
            trigger: 'blur'
          }
        ],
        dazi_number: [
          {
            required: true,
            message: '请输入搭子数量',
            trigger: 'blur'
          }
        ],
        circle_number: [
          {
            required: true,
            message: '请输入圈子数量',
            trigger: 'blur'
          }
        ],
        service_number: [
          {
            required: true,
            message: '请输入服务数量',
            trigger: 'blur'
          }
        ],
        community_number: [
          {
            required: true,
            message: '请输入社群数量',
            trigger: 'blur'
          }
        ]
        // // 站点 图片上传
        // img: [
        //   { required: true, validator: categoryImage, trigger: 'change' }
        // ]
      },
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false,
      showChoose: false,
      orderInfoData: null,
      showTextarea: false,
      textarea: '',
      remark: '',
      is_authentication: 2,
      averageScore: ''
    };
  },
  activated () { },
  computed: {
    orderStatusFn: function () {
      return function (status) {
        let orderStatus = '';
        // 1 待接单 2 接单中 3 完成 4 已结算 4拒绝订单
        orderStatus =
          status == 0
            ? '未提交'
            : status == 1
              ? '待审核'
              : status == 2
                ? '审核通过'
                : '驳回';

        return orderStatus;
      };
    },
    scoreStatusFn () {
      return function (technology_score, service_score, voice_score) {
        let score;

        score = ((technology_score + service_score + voice_score) / 3).toFixed(
          2
        );
        console.log(score);
        this.averageScore = score;

        return '';
      };
    }
  },
  methods: {
    partnerUserFn (row) {
      if (row?.id) {
        // const res = await siteCategoriesDetail(row.id);

        this.currentPromoters = row;
        // 用户余额管理
        this.drawerEditBoolenPromoters = !this.drawerEditBoolenPromoters;
      } else {
        this.drawerEditBoolenPromoters = !this.drawerEditBoolenPromoters;
        this.currentPromoters = null;
      }
    },
    imgScare (imgStr) {
      console.log(imgStr);
      if (imgStr.length) {
        if (imgStr.includes(',')) {
          console.log('字符串中包含逗号');
          // 包含的进行slice(',') 分割

          this.imgViewArr = imgStr.split(',').map((item) => item.trim());
        } else {
          console.log('字符串中不包含逗号');
          this.imgViewArr = imgStr.split();
        }

        this.viewerVisible = true;
      } else {
        this.$message({
          message: '没有上传图片无法进行预览',
          type: 'warning'
        });
      }
    },

    inputChange (e) {
      console.log(e);
      if (e == 3) {
        this.showTextarea = true;
        this.is_authentication = e;
      } else {
        this.showTextarea = false;
        this.is_authentication = e;
        this.remark = null;
      }
    },
    // 关闭抽屉
    handleClose () {
      console.log('查看详情');
      this.$emit('update:drawerEditBoolen', false);
    },
    // 获取存储配置
    // async storageConfig () {
    //   const res = await storageConfigDetail();

    //   // console.log(res.storageMode);

    //   this.storageMode = res?.storageMode;
    // },
    // 关闭查看器
    closeViewer () {
      this.viewerVisible = false;
    },
    // 下载图片
    handleDownload (file) {
      window.open(file.url);
    },
    // 删除图片
    handleRemove () {
      this.fileList = [];
      this.imageUrl = '';
      this.form.img = this.imageUrl;
    },
    //  图片上传个数超过限制
    exceedFn () {
      this.$message({
        message: '图片上传已达到上限,请删除后再上传',
        type: 'warning'
      });
    },

    async handleFileChange (file) {
      this.aliFn(file);
    },
    // 阿里云
    async aliFn (file) {
      this.loading = true;

      let files = file.raw;

      console.log(files);
      // 构建请求参数
      let params = new FormData();
      console.log(params);

      //   params.append('signature', '132321313');
      params.append('file', files);
      console.log(params);

      //   let config = {
      //     headers: {
      //       'Access-Control-Allow-Origin': '*',
      //       'x-oss-callback-Authorization': getToken()
      //     }
      //   };

      const res = await upload(params);
      //   let result = await axios.post(res.host, param, config);
      //   let url = res.host + '/' + date + suffix;
      console.log(res);
      if (res.code == 0) {
        this.form.img = res.data.url;
        this.loading = false;
      }
      //   this.form.categoryImages = url;
      //   this.imageUrl = url;
      //   this.loading = false;
    },

    /* 保存编辑 */
    save () {
      this.loading = true;

      const saveOrUpdate = authentication;
      saveOrUpdate({
        is_authentication: this.is_authentication,
        id: this.orderInfoData.id,
        remark: this.remark
      })
        .then((msg) => {
          console.log(msg);
          this.loading = false;
          this.$message.success(msg.message);

          this.handleClose();
          this.$emit('done');
        })
        .catch((e) => {
          this.loading = false;
          this.$message.error(e.message);
        });
    }
    /* 更新visible */
  },
  watch: {
    drawerEditBoolen (visible) {
      this.$nextTick(async () => {
        if (visible) {
          console.log(this.data);
          if (this.data) {
            // this.orderInfoData = this.data

            const res = await associateGetInfo({ user_id: this.data.user_id });

            console.log(res);
            if (res.code == 0) {
              this.orderInfoData = res.data;


              console.log(this.orderInfoData);
            } else {
              this.$message.error(res.message);
            }

            if (this.data.is_authentication == 3) {
              this.radio = 3;
              this.is_authentication = 3;
              this.remark = this.data.remark;
              this.showTextarea = true;
            } else {
              this.radio = 2;
              this.is_authentication = 2;
              this.remark = null;
              this.showTextarea = false;
            }

            this.isUpdate = true;
          } else {
            this.isUpdate = false;
          }
        }
      });
    }
  }
};
  </script>
  
  <style lang="less" scoped>
.realNameStyle {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  .avaterName {
    width: 32px;
    height: 32px;
    border-radius: 32px;
    vertical-align: middle;
    margin-right: 5px;
  }
}
.line {
  width: 5px;
  height: 15px;
  border-radius: 53px;
  margin-right: 5px;
  background: #0084ff;
}
/*隐藏input（type=number)右边的小箭头*/
/deep/.delInput input::-webkit-outer-spin-button,
/deep/.delInput input::-webkit-inner-spin-button {
  -webkit-appearance: none !important;
}
/deep/.delInput input[type='number'] {
  -moz-appearance: textfield;
}
/deep/.el-textarea__inner {
  margin-top: 20px;
  min-height: 150px !important;
}
.img {
  width: 42px;
  height: 42px;
}

.detailsText {
  margin: 10px 0 10px 43px;
  .evaluateImg {
    width: 90px;
    height: 90px;
    // border-radius: 20px;
    margin-top: 5px;
  }
}
.lifeImg {
  width: 90px;
  height: 90px;
  padding: 10px 10px 10px 0px;
}
.evaluateList {
  margin-bottom: 23px;

  .img {
    width: 42px;
    height: 42px;
    border-radius: 50%;
  }

  .detailsText {
    margin: 10px 0 10px 43px;
  }
}
.threePoints {
  width: 16px;
  height: 16px;
}
.foodsDiv div {
  margin-left: 20px;
  margin-top: 10px;
}
.height83 {
  height: 83vh;
}
.hLabel {
  margin: 10px 0 20px;
  font-weight: 700;
  &::before {
    content: '';
    display: inline-block;
    vertical-align: top;

    margin-right: 5px;
    height: 23px;
    width: 6px;
    background-color: #1e6ceb;
  }
}
.drawer__footer {
  display: flex;
  justify-content: flex-start;
  margin-left: 15px;
}
</style>
  